package com.bugstack.springframework.beans.factory.support;

import com.bugstack.springframework.beans.BeansException;
import com.bugstack.springframework.beans.factory.config.BeanDefinition;

import java.util.HashMap;
import java.util.Map;


/**
 * 注册Bean定义与获取Bean定义就可以同时使用了
 */
public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory implements BeanDefinitionRegistry{

    private Map<String,BeanDefinition> beanDefinitionMap = new HashMap<>();


    @Override
    public BeanDefinition getBeanDefinition(String beanName) {//获取bean的定义
        BeanDefinition beanDefinition = beanDefinitionMap.get(beanName);
        if(beanDefinition==null){
            throw new BeansException("No bean named");
        }
        return beanDefinition;
    }


    @Override
    public void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) {//注册bean的定义
        beanDefinitionMap.put(beanName,beanDefinition);

    }
}
